package com.yichi;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yichi.R;
import com.yichi.adapter.BatteryAdapter;
import com.yichi.model.BatteryTypeModel;
import com.yichi.service.DeviceService;

import java.util.ArrayList;

public class ModeActivity extends AppCompatActivity {

    private BatteryAdapter batteryAdapter;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_mode);

        initView();
        loadData();
    }

    private void loadData() {
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        batteryAdapter = new BatteryAdapter(DeviceService.inst.batteryStoreList, ModeActivity.this);
        recyclerView.setAdapter(batteryAdapter);
    }

    private void initView() {
        ImageView iv_add = findViewById(R.id.iv_add);
        ImageView iv_back = findViewById(R.id.iv_back);

        //添加
        iv_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                batteryAdapter.showSetDialog(-1);
            }
        });
        //返回
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
